import { Controller, Post, Body, Inject } from '@nestjs/common';
import { AuthService } from './auth.service';
import { ApiTags, ApiResponse, ApiOperation } from '@nestjs/swagger';
import { SigninUserVo } from 'src/pojo/vo/signinuser.vo';
import { BasicVo } from 'src/pojo/vo/basic.vo';
import { SigninUserDto } from 'src/pojo/dto/signinuser.dto';
import { GetUserAgent, GetUserIp } from 'src/utils/GetUserMessTool';
import { SecretTool } from 'src/utils/SecretTool';

@ApiTags('认证模块')
@Controller('auth/v1')
export class AuthController {
  @Inject()
  private secretTool: SecretTool;

  @Inject()
  private authService: AuthService;

  @ApiOperation({ summary: '登录' })
  @ApiResponse({
    status: 200,
    type: SigninUserVo,
    description: 'data数据',
  })
  @ApiResponse({
    status: 201,
    description: '通用数据',
    type: BasicVo,
  })
  @Post('login')
  signIn(
    @Body() signinUserDto: SigninUserDto,
    @GetUserIp() ip: string,
    @GetUserAgent() agent: string,
  ): Promise<SigninUserVo> {
    const key = this.secretTool.getSecret(ip + agent);
    return this.authService.signIn(signinUserDto, key);
  }
}
